func mySqrt(x int) int {
    left, right := 0, x/2 + 1
    for left <= right {
        middle := (left+right)/2
        if middle*middle > x {
            right = middle - 1
        } else {
            left = middle + 1
        }
    }
    return right
}